﻿using System;
using System.Collections.Generic;
using System.Linq;
using Com.PhilChuang.Mobile.Apps.LocationSender.Ui.Views.Impl.ViewModels;
using Com.PhilChuang.Pmvp.Ui.Views.Impl.ViewModels;
using Microsoft.Phone.Controls.Maps;
using Microsoft.Phone.Shell;

namespace Com.PhilChuang.Mobile.Apps.LocationSender.Ui.Views.Impl.Pages
{
	public sealed partial class WelcomePage : WelcomePageBase
	{
		#region Events
		public event Action DoSelectContacts = delegate { };
		public event Action DoResend = delegate { };
		public event Action DoOpenAboutView = delegate { };
		public event Action DoLaunchAppRateLink = delegate { };
		public event Action DoOpenSettingsView = delegate { }; 
		#endregion

		#region Instance members (EMPTY)
		#endregion

		#region Properties (EMPTY)
		#endregion

		#region Constructors / Init
		public WelcomePage ()
		{
			InitializeComponent ();
			SetApplicationBarItems ();
		}
		#endregion

		#region Event handlers
		private void g_btn_SelectContacts_Click (object sender, System.Windows.RoutedEventArgs e)
		{
			DoSelectContacts ();
		}

		private void g_btn_Resend_Click (object sender, EventArgs e)
		{
			DoResend ();
		}

		private void g_btn_Settings_Click (object sender, EventArgs e)
		{
			DoOpenSettingsView ();
		}

		private void g_btn_About_Click (object sender, EventArgs e)
		{
			DoOpenAboutView ();
		}

		private void g_btn_RateThisApp_Click (object sender, EventArgs e)
		{
			DoLaunchAppRateLink ();
		}
		#endregion

		#region Functionality (EMPTY)
		#endregion

		#region Private methods
		protected override void SetApplicationBarItems ()
		{
			g_btn_Resend = (ApplicationBarIconButton) ApplicationBar.Buttons[0];
			g_btn_Settings = (ApplicationBarIconButton) ApplicationBar.Buttons[1];

			g_btn_About = (ApplicationBarMenuItem) ApplicationBar.MenuItems[0];
			g_btn_RateThisApp = (ApplicationBarMenuItem) ApplicationBar.MenuItems[1];
		}

		protected override bool UpdateApplicationBarItemsWhen (string propertyName)
		{
			return base.UpdateApplicationBarItemsWhen (propertyName)
				   || propertyName == INPCHelper.GetPropertyName (() => ViewModel.UseLastRecipientsAndFormatButtonEnabled);
		}

		protected override void UpdateApplicationBarItems ()
		{
			base.UpdateApplicationBarItems ();
			g_btn_Resend.IsEnabled = ViewModel.UseLastRecipientsAndFormatButtonEnabled;
		}

		protected override Map MapControl { get { return g_Map; } }
		#endregion

		#region Utility methods
		#endregion
	}

	public class WelcomePageBase : AbstractLocationSenderAppPageBase<WelcomePageViewModel>
	{
		protected override Map MapControl { get { return null; } }
	}
}